home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 4 / FM Towns Free Software Collection 4 - Disc 1.iso / t_os / border / source / cons3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-19  |  23.4 KB  |  1,008 lines

  1. /******************************
  2.  *    Consol Low I/O        *
  3.  ******************************/
  4. #include    <stdio.h>
  5. #include    <stdlib.h>
  6. #include    <stdarg.h>
  7. #include    <string.h>
  8. #include    <ctype.h>
  9. #include    <egb.h>
  10. #include    <fmc.h>
  11. #include    "oaklib.h"
  12. #include    "dabe.h"
  13.  
  14. extern char work[];
  15.  
  16. #define    PIX_BYTE 1    /* 画面モ-ドにより変化 16色=1 256色=1 32K色=2 */
  17.  
  18. #define    TOP_X    wp->top_x
  19. #define    TOP_Y    wp->top_y
  20. #define    BTM_X    wp->btm_x
  21. #define    BTM_Y    wp->btm_y
  22. #define    SIZ_X    wp->siz_x
  23. #define    SIZ_Y    wp->siz_y
  24. #define    CUR_X    wp->cur_x
  25. #define    CUR_Y    wp->cur_y
  26. #define    CHR_COL    wp->chr_col
  27. #define    CHR_BAK    wp->chr_bak
  28. #define    CUR_COL    wp->cur_col
  29. #define    BAK_COL    wp->bak_col
  30. #define    FNT_X    wp->fnt_x
  31. #define    FNT_Y    wp->fnt_y
  32. #define    FNT_STL    wp->fnt_stl
  33. #define    KAN_COD    wp->kan_cod
  34. #define    DSP_X    wp->dsp.x
  35. #define    DSP_Y    wp->dsp.y
  36. #define    DSP_LEN    wp->dsp.len
  37. #define    DSP_BUF    wp->dsp.buf
  38.  
  39. typedef struct _WP {
  40.     struct _WP *next;
  41.     short    top_x,top_y;
  42.     short    btm_x,btm_y;
  43.     short    siz_x,siz_y;
  44.     short    cur_x,cur_y;
  45.     short    chr_col,chr_bak;
  46.     short    cur_col,bak_col;
  47.     short    fnt_x,fnt_y,fnt_stl;
  48.     short    kan_cod;
  49.     struct {
  50.         short    x,y;
  51.         short    len;
  52.         char    buf[256];
  53.     } dsp;
  54. } WIND;
  55.  
  56. WIND    *act_wind=NULL;
  57.  
  58. static int      bch=0;
  59. static unsigned bec=0;
  60.  
  61. extern    short    INS_STAT;        
  62. static    char    charmap[40][100];
  63. static    short    charmap2[40][100];
  64. static    short    LOC_Y;
  65. static    short    MAX_X[40];
  66. static    short    MAX_Y;
  67.  
  68.  
  69. void    init_charmap(void)
  70. {
  71.     register WIND *wp=act_wind;
  72.     short    i;
  73.     char    *pcharmap;
  74.     
  75.     for( i = 0; i < 40; i++ ){
  76.         pcharmap = &charmap[i][0];
  77.         *pcharmap = 0x00;
  78.         MAX_X[i] = (-1);
  79.     }     
  80.     KAN_COD = 0;
  81. }
  82.  
  83. short    kbhit(void)
  84. {
  85.     if ( (bch != 0xFFFF) || ( (bch = KAN_read(1,&bec) ) != 0xFFFF) )
  86.         return 1;
  87.     else
  88.         return 0;
  89. }
  90.  
  91. short    getch(void)
  92. {
  93.     short   ch;
  94.     short    ret;
  95.         
  96.     while ( (ret = kbhit()) == 0 && put_oakcur() == 0 );
  97.     if( ret == 0 ) 
  98.         return    ESC;
  99.     else{    
  100.         ch = bch; bch = 0xFFFF;
  101.         return ch;
  102.     }
  103. }
  104.  
  105.  
  106. void    cur_dsp(sw)
  107. short    sw;
  108. {
  109.     register WIND *wp=act_wind;
  110.     char    para[8];
  111.  
  112.     EGB_writePage( work, 0x40 );
  113.     EGB_paintMode(work,0x02);
  114.     EGB_color(work,0,sw == 0 ? CUR_COL:CHR_BAK);
  115.     WORD(para+0) = DSP_X;
  116.     WORD(para+2) = DSP_Y + 1;
  117.     WORD(para+4) = DSP_X + FNT_X - 1;
  118.     WORD(para+6) = DSP_Y + 1;
  119.     EGB_rectangle(work,para);
  120.     EGB_paintMode(work,0x22);
  121. }
  122.  
  123. void    chr_bak(void)
  124. {
  125.     register WIND *wp=act_wind;
  126.     char    para[8];
  127.  
  128.     if ( DSP_LEN <= 0 )
  129.     return;
  130.     EGB_paintMode(work,0x22);
  131.     EGB_color(work,0,CHR_BAK);
  132.     EGB_color(work,2,CHR_BAK);
  133.     WORD(para+0) = DSP_X;
  134.     WORD(para+2) = DSP_Y;
  135.     WORD(para+4) = DSP_X + FNT_X * DSP_LEN + ((FNT_STL & 2) ? 2:-1);
  136.     WORD(para+6) = DSP_Y - (FNT_Y - 2);
  137.     EGB_rectangle(work,para);
  138. }
  139.  
  140. void    cflush(void)
  141. {
  142.     register WIND *wp=act_wind;
  143.  
  144.     cur_dsp(1);
  145.     chr_bak();
  146.     EGB_color(work,0,CHR_COL);
  147.     EGB_textSpace(work,FNT_X - 8);
  148.     EGB_fontStyle(work,FNT_STL);
  149.     EGB_sjisString(work,(char *)&(wp->dsp));
  150.     DSP_X = CUR_X * FNT_X + TOP_X;
  151.     DSP_Y = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2);
  152.     DSP_LEN = 0;
  153.     cur_dsp(0);
  154. }
  155.  
  156.  
  157. WIND    *wind(short x1,short y1,short x2,short y2,
  158.           short col,short bak,short cur,
  159.           short fx,short fy,short stl)
  160. {
  161.     register WIND *wp;
  162.     char    para[8];
  163.  
  164.     if ( (wp = (WIND *)malloc(sizeof(WIND))) == NULL )
  165.     return NULL;
  166.  
  167.     wp->next = act_wind;
  168.     act_wind = wp;
  169.  
  170.     EGB_writePage( work, 0x40 );
  171.     EGB_paintMode(work,0x22);
  172.     EGB_color(work,0,col);
  173.     EGB_color(work,2,bak);
  174.     WORD(para+0) = x1;
  175.     WORD(para+2) = y1;
  176.     WORD(para+4) = x2;
  177.     WORD(para+6) = y2;
  178.     EGB_rectangle(work,para);
  179.  
  180.     x1 += 2; y1 += 2; x2 -= 2; y2 -= 2;
  181.  
  182.     TOP_X = x1;
  183.     TOP_Y = y1;
  184.     BTM_X = x2;
  185.     BTM_Y = y2;
  186.     FNT_X = fx;
  187.     FNT_Y = fy;
  188.     FNT_STL = stl;
  189.     SIZ_X = (x2 - x1 + ((stl & 2) ? -2:1)) / FNT_X;
  190.     SIZ_Y = (y2 - y1 + 1) / FNT_Y;
  191.     CUR_X = 0;    CUR_Y = 0;    LOC_Y = 0;    MAX_Y = 0;
  192.     CHR_COL = col;
  193.     CHR_BAK = BAK_COL = bak;
  194.     CUR_COL = cur;
  195.     KAN_COD = 0;
  196.     DSP_X = TOP_X;
  197.     DSP_Y = TOP_Y + (FNT_Y - 2);
  198.     DSP_LEN = 0;
  199.     cur_dsp(0);
  200.  
  201.     return wp;
  202. }
  203.  
  204. void    locate(short x,short y)
  205. {
  206.     register WIND *wp=act_wind;
  207.  
  208.     if ( (CUR_X = x) >= SIZ_X )
  209.         CUR_X = SIZ_X - 1;
  210.     if ( (CUR_Y = y) >= SIZ_Y )
  211.         CUR_Y = SIZ_Y - 1;
  212.     cflush();
  213. }
  214.  
  215. void    color(short col)
  216. {
  217.     register WIND *wp=act_wind;
  218.  
  219.     CHR_COL = col;
  220. }
  221.  
  222. void    roll_up()
  223. {
  224.     register WIND *wp=act_wind;
  225.     char    p[120];
  226.     
  227.     cflush();
  228.    
  229.     cur_dsp(1);
  230.     
  231.     WORD(p + 0) = TOP_X;
  232.     WORD(p + 2) = TOP_Y;
  233.     WORD(p + 4) = BTM_X;
  234.     WORD(p + 6) = ( SIZ_Y - 1 ) * FNT_Y + TOP_Y + (FNT_Y - 2);
  235.     EGB_color( work, 1, BAK_COL);
  236.     EGB_partScroll( work, 1, 0, FNT_Y, p );
  237.     
  238.     EGB_color(work, 0, CHR_COL);
  239.        WORD( p + 0 ) = TOP_X;
  240.     WORD( p + 2 ) = TOP_Y + (FNT_Y - 2);
  241.     WORD( p + 4 ) = MAX_X[LOC_Y] + 1;
  242.     strncpy( ( p + 6 ), &charmap[LOC_Y][0], MAX_X[LOC_Y] + 1);
  243.     EGB_sjisString( work, p );
  244.     
  245.     cur_dsp(0);
  246. }
  247.  
  248. void    roll_down()
  249. {
  250.     register WIND *wp=act_wind;
  251.     char    p[120];
  252.     
  253.     cflush();
  254.     
  255.     cur_dsp(1);
  256.     
  257.     WORD(p + 0) = TOP_X;
  258.     WORD(p + 2) = TOP_Y;
  259.     WORD(p + 4) = BTM_X;
  260.     WORD(p + 6) = ( SIZ_Y - 1 ) * FNT_Y + TOP_Y + (FNT_Y - 2);
  261.     EGB_color( work, 1, BAK_COL);
  262.     EGB_partScroll( work, 1, 0, -FNT_Y, p );
  263.     
  264.     EGB_color(work, 0, CHR_COL);
  265.     WORD( p + 0 ) = TOP_X;
  266.     WORD( p + 2 ) = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2);
  267.     WORD( p + 4 ) = MAX_X[LOC_Y] + 1;
  268.     strncpy( ( p + 6 ), &charmap[LOC_Y][0], MAX_X[LOC_Y] + 1);
  269.     EGB_sjisString( work, p );
  270.     
  271.     cur_dsp(0);
  272. }
  273.  
  274. void    roll_left( short    byte )
  275. {    
  276.     register WIND *wp=act_wind;
  277.     char    para[8];
  278.     
  279.        cur_dsp(1);
  280.     EGB_color(work, 1, BAK_COL);
  281.     
  282.     WORD(para + 0) = CUR_X * FNT_X + TOP_X;
  283.     WORD(para + 2) = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2) - 16;
  284.     WORD(para + 4) = BTM_X;
  285.     WORD(para + 6) = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2);
  286.     EGB_partScroll(work, 1, -FNT_X * byte, 0, para);
  287.        
  288.        cur_dsp(0);
  289. }
  290.  
  291. void    roll_left2( short byte, short linecount )
  292. {    
  293.     register WIND *wp=act_wind;
  294.     char    para[8];
  295.     
  296.        cur_dsp(1);
  297.     EGB_color(work, 1, BAK_COL);
  298.     
  299.     WORD(para + 0) = TOP_X;
  300.     WORD(para + 2) = (CUR_Y + linecount) * FNT_Y + TOP_Y + (FNT_Y - 2) - 16;
  301.     WORD(para + 4) = BTM_X;
  302.     WORD(para + 6) = (CUR_Y + linecount) * FNT_Y + TOP_Y + (FNT_Y - 2);
  303.     EGB_partScroll(work, 1, -FNT_X * byte, 0, para);
  304.        
  305.        cur_dsp(0);
  306. }
  307.  
  308. void     roll_right()
  309. {
  310.     register WIND *wp=act_wind;
  311.     char    para[8];
  312.     
  313.        cur_dsp(1);
  314.     
  315.     WORD(para + 0) = CUR_X * FNT_X + TOP_X;
  316.     WORD(para + 2) = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2) - 16;
  317.     WORD(para + 4) = (MAX_X[LOC_Y] + 1) * FNT_X + TOP_X;
  318.     WORD(para + 6) = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2);
  319.     EGB_color(work, 1, BAK_COL);
  320.     EGB_partScroll(work, 1, FNT_X, 0, para);
  321.        
  322.     if( (MAX_X[LOC_Y] + 1) < BTM_X ){
  323.         WORD(para + 0) = (MAX_X[LOC_Y] + 1) * FNT_X + TOP_X;
  324.         WORD(para + 2) = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2) - 16;
  325.         WORD(para + 4) = BTM_X;
  326.         WORD(para + 6) = CUR_Y * FNT_Y + TOP_Y + (FNT_Y - 2);
  327.            EGB_paintMode(work,0x22);
  328.         EGB_color(work, 0, BAK_COL);
  329.         EGB_color(work, 2, BAK_COL);
  330.         EGB_rectangle(work, para);
  331.     }
  332.         
  333.        cur_dsp(0);
  334. }
  335.  
  336. void     roll_right2( short  linecount, short    byte )
  337. {
  338.     register WIND *wp=act_wind;
  339.     char    para[8];
  340.     
  341.        cur_dsp(1);
  342.     
  343.     WORD(para + 0) = TOP_X;
  344.     WORD(para + 2) = (CUR_Y + linecount) * FNT_Y + TOP_Y + (FNT_Y - 2) - 16;
  345.     WORD(para + 4) = (MAX_X[LOC_Y + linecount] + 1) * FNT_X + TOP_X;
  346.     WORD(para + 6) = (CUR_Y + linecount) * FNT_Y + TOP_Y + (FNT_Y - 2);
  347.     EGB_color(work, 1, BAK_COL);
  348.     EGB_partScroll(work, 1, (FNT_X * byte), 0, para);
  349.        
  350.     if( (MAX_X[LOC_Y + linecount] + 1) < BTM_X ){
  351.         WORD(para + 0) = (MAX_X[LOC_Y + linecount] + 1) * FNT_X + TOP_X;
  352.         WORD(para + 2) = (CUR_Y + linecount) * FNT_Y + TOP_Y + (FNT_Y - 2) - 16;
  353.         WORD(para + 4) = BTM_X;
  354.         WORD(para + 6) = (CUR_Y + linecount) * FNT_Y + TOP_Y + (FNT_Y - 2);
  355.         EGB_paintMode(work,0x22);
  356.         EGB_color(work, 0, BAK_COL);
  357.         EGB_color(work, 2, BAK_COL);
  358.         EGB_rectangle(work, para);
  359.     }
  360.        cur_dsp(0);
  361. }
  362.  
  363. short    kanji_twoback()
  364. {
  365.        register WIND *wp=act_wind;
  366.        
  367.        if( charmap2[LOC_Y][CUR_X - 2] == 1 )
  368.         return    1;
  369.     else
  370.         return    0;        
  371. }
  372.  
  373. short    kanji_here()
  374. {
  375.        register WIND *wp=act_wind;
  376.        
  377.        if( charmap2[LOC_Y][CUR_X] == 1 )
  378.         return    1;
  379.     else
  380.         return    0;        
  381. }
  382.  
  383. short    kanji_move( short    linecount )
  384. {
  385.        register WIND *wp=act_wind;
  386.        
  387.        if( charmap2[LOC_Y + linecount][0] == 1 )
  388.         return    1;
  389.     else
  390.         return    0;        
  391. }
  392.  
  393. short    cur_left(void)
  394. {
  395.     register WIND *wp=act_wind;
  396.     
  397.     if( ( LOC_Y > 0 ) || ( CUR_X > 0 ) ){
  398.         if( CUR_X <= 0 ){
  399.             if( --LOC_Y < 0 )
  400.                 LOC_Y = 0;
  401.             else {    
  402.                 CUR_X = strlen( &charmap[LOC_Y][0] );
  403.                 if( kanji_twoback() )
  404.                     CUR_X -= 2;
  405.                 else
  406.                     CUR_X--;    
  407.                 if ( --CUR_Y < 0 ) {
  408.                     CUR_Y = 0;
  409.                     roll_up();
  410.                 }
  411.             }
  412.         } else {
  413.             if( kanji_twoback() )
  414.                 CUR_X--;
  415.             CUR_X--;
  416.         }
  417.         return    1;
  418.     } else
  419.         return     0;
  420. }
  421.  
  422. void    cur_right(void)
  423. {
  424.     register WIND *wp=act_wind;
  425.     
  426.     if( ( MAX_X[LOC_Y] >= CUR_X ) || ( MAX_Y > LOC_Y ) ){
  427.         if( kanji_here() ){
  428.                if( ( CUR_X == ( MAX_X[LOC_Y] - 1 ) ) && ( MAX_Y > LOC_Y ) ){
  429.                 CUR_X = 0;    
  430.                 if( ++LOC_Y > MAX_Y )
  431.                     MAX_Y = LOC_Y;
  432.                 if( ++CUR_Y >= SIZ_Y ) {
  433.                        CUR_Y = SIZ_Y - 1;
  434.                        roll_down();
  435.                 } 
  436.             } else
  437.                 CUR_X += 2;
  438.         } else {
  439.                if( ( CUR_X == MAX_X[LOC_Y] ) && ( MAX_Y > LOC_Y ) ){
  440.                 CUR_X = 0;
  441.                 if( ++LOC_Y > MAX_Y )
  442.                     MAX_Y = LOC_Y;
  443.                 if( ++CUR_Y >= SIZ_Y ) {
  444.                        CUR_Y = SIZ_Y - 1;
  445.                        roll_down();
  446.                 } 
  447.                 } else
  448.                 CUR_X++;
  449.         }            
  450.     }
  451. }
  452.  
  453. void    cur_up()
  454. {
  455.     register WIND *wp=act_wind;
  456.     short    *pcharmap2;
  457.     
  458.     if( LOC_Y > 0 ){
  459.         LOC_Y--;
  460.         if( CUR_X > MAX_X[LOC_Y] )
  461.               CUR_X = MAX_X[LOC_Y];
  462.           pcharmap2 = &charmap2[LOC_Y][CUR_X];
  463.         if( *pcharmap2 == 2 )
  464.             CUR_X--;
  465.         if ( --CUR_Y < 0 ) {
  466.             CUR_Y = 0;
  467.             roll_up();
  468.         }
  469.     }
  470. }
  471.  
  472. void    cur_down()
  473. {
  474.     register WIND *wp=act_wind;
  475.     short    *pcharmap2;
  476.      
  477.     if( LOC_Y < MAX_Y ){
  478.         LOC_Y++;
  479.         if( CUR_X > MAX_X[LOC_Y] ){
  480.               if( MAX_X[LOC_Y] < 0 )
  481.                   CUR_X = 0;
  482.               else
  483.                   CUR_X = MAX_X[LOC_Y];
  484.           }
  485.           pcharmap2 = &charmap2[LOC_Y][CUR_X];
  486.         if( *pcharmap2 == 2 )
  487.             CUR_X--;
  488.         if ( ++CUR_Y >= SIZ_Y ) {
  489.             CUR_Y = SIZ_Y - 1;
  490.             roll_down();
  491.         }
  492.     }
  493.      
  494. }
  495.  
  496.  
  497. void    smemcpy( short *mem1, short *mem2, short byte )
  498. {
  499.     short    i;
  500.     
  501.     for( i = 1; i <= byte; i++ ){
  502.         *mem1 = *mem2;
  503.         mem1++;
  504.         mem2++;
  505.     }    
  506. }
  507.  
  508. void    cmemcpy( char *mem1, char *mem2, short byte )
  509. {
  510.     short    i;
  511.     
  512.     for( i = 1; i <= byte; i++ ){
  513.         *mem1 = *mem2;
  514.         mem1++;
  515.         mem2++;
  516.     }    
  517. }
  518.  
  519. void    cmemset( char *mem, char chr, short byte )
  520. {
  521.     short    i;
  522.     
  523.     for( i = 1; i <= byte; i++ ){
  524.         *mem = chr;
  525.         mem++;
  526.     }    
  527. }
  528.  
  529. void    move_left( short byte, short linecount )
  530. {
  531.        register WIND *wp=act_wind;
  532.        char    p[8];
  533.        
  534.        if( ( CUR_Y + linecount ) <= ( SIZ_Y - 1 ) ) 
  535.            roll_left2( byte, linecount );
  536.     
  537.        if( ( CUR_Y + linecount - 1 ) <= ( SIZ_Y - 1 ) ){ 
  538.            WORD( p + 0 ) = ( MAX_X[LOC_Y + linecount - 1] + 1 ) * FNT_X + TOP_X;
  539.         WORD( p + 2 ) = (CUR_Y + linecount - 1 ) * FNT_Y + TOP_Y + (FNT_Y - 2);
  540.            WORD( p + 4 ) = byte;
  541.         strncpy( ( p + 6 ), &charmap[LOC_Y + linecount][0], byte );
  542.         EGB_sjisString( work, p );
  543.     }
  544.           
  545.       strncat( &charmap[LOC_Y + linecount - 1][0], &charmap[LOC_Y + linecount][0], byte);
  546.       smemcpy( &charmap2[LOC_Y + linecount - 1][ MAX_X[LOC_Y + linecount - 1] + 1 ], &charmap2[LOC_Y + linecount][0], byte);
  547.     MAX_X[LOC_Y + linecount - 1] = strlen( &charmap[LOC_Y + linecount - 1][0] ) - 1; 
  548.     
  549.     strcpy( &charmap[LOC_Y + linecount][0], &charmap[LOC_Y + linecount][byte] );
  550.     smemcpy( &charmap2[LOC_Y + linecount][0], &charmap2[LOC_Y + linecount][byte], 80 - byte); 
  551.     MAX_X[LOC_Y + linecount] = strlen( &charmap[LOC_Y + linecount][0] ) - 1; 
  552.     
  553. }
  554.  
  555. void    del(void)
  556. {
  557.     register WIND *wp=act_wind;
  558.        short        byte;
  559.        short        linecount;
  560.        short        freelen;
  561.            
  562.        if( kanji_here() )
  563.            byte = 2;
  564.        else
  565.            byte = 1;    
  566.        strcpy( &charmap[LOC_Y][CUR_X], &charmap[LOC_Y][CUR_X + byte] );    
  567.       smemcpy( &charmap2[LOC_Y][CUR_X], &charmap2[LOC_Y][CUR_X + byte], 80 - ( CUR_X + byte ) );
  568.     MAX_X[LOC_Y] = strlen( &charmap[LOC_Y][0] ) - 1; 
  569.     roll_left( byte );
  570.            
  571.        linecount = 1;
  572.        while( ( LOC_Y + linecount ) <= MAX_Y ){ 
  573.         if( MAX_X[LOC_Y + linecount] >= 0 ){
  574.             freelen = (SIZ_X - 1) - strlen( &charmap[ LOC_Y + linecount - 1 ][0] ) + 1 ;
  575.             switch( freelen ){
  576.                 case 3:    if( kanji_move( linecount ) ){
  577.                             move_left( 2, linecount );
  578.                             if( kanji_move( linecount ) == 0 )
  579.                                 move_left( 1, linecount );
  580.                         } else {
  581.                             move_left( 1, linecount );
  582.                             if( kanji_move( linecount ) )
  583.                                 move_left( 2, linecount );
  584.                             else    
  585.                                 move_left( 1, linecount );
  586.                         }    
  587.                         break;            
  588.                 case 2:    if( kanji_move( linecount ) )
  589.                             move_left( 2, linecount );
  590.                         else {
  591.                             move_left( 1, linecount );
  592.                             if( kanji_move( linecount ) == 0 )
  593.                                 move_left( 1, linecount );
  594.                         }    
  595.                         break;
  596.                 case 1:    if( kanji_move( linecount ) == 0 )
  597.                             move_left( 1, linecount );
  598.                         break;            
  599.                 default:
  600.                     break;
  601.             }
  602.             linecount++;
  603.         } else
  604.             MAX_Y--;
  605.     }
  606.     
  607. }
  608.  
  609. void    move_putchr( short linecount, short insbyte )
  610. {
  611.        register WIND *wp=act_wind;
  612.        char    p[12];
  613.        
  614.     if( linecount == 0 )
  615.         roll_right();    
  616.     else {    
  617.         roll_right2( linecount, insbyte );
  618.            WORD( p + 0 ) = TOP_X;
  619.         WORD( p + 2 ) = (CUR_Y + linecount) * FNT_Y + TOP_Y + (FNT_Y - 2);
  620.            WORD( p + 4 ) = insbyte;
  621.         strncpy( ( p + 6 ), &charmap[LOC_Y + linecount][0], insbyte);
  622.         EGB_color(work, 0, CHR_COL);
  623.         EGB_sjisString( work, p );
  624.     }
  625. }
  626.  
  627. void    move_right( short movebyte, short linecount )
  628. {
  629.        register WIND *wp=act_wind;
  630.        char    *pcharmap;    
  631.        
  632.     MAX_X[LOC_Y + linecount] = MAX_X[LOC_Y + linecount] - movebyte; 
  633.     _rstrcpy( &charmap[LOC_Y + linecount + 1][movebyte], &charmap[LOC_Y + linecount + 1][0] );
  634.       pcharmap = &charmap[LOC_Y + linecount][ MAX_X[LOC_Y + linecount] + 1];
  635.       cmemcpy( &charmap[LOC_Y + linecount + 1][0], pcharmap, movebyte); 
  636.       *pcharmap = (char)0x00;
  637.     _rmemcpy( &charmap2[LOC_Y + linecount + 1][movebyte], &charmap2[LOC_Y + linecount + 1][0], (80 - movebyte) * 2); 
  638.       smemcpy( &charmap2[LOC_Y + linecount + 1][0], &charmap2[LOC_Y + linecount][ MAX_X[LOC_Y + linecount] + 1], movebyte); 
  639.        
  640. }
  641.  
  642. void    ins()
  643. {
  644.     register WIND *wp=act_wind;
  645.     short    insbyte;
  646.     short    movebyte;
  647.     short    *pcharmap2;
  648.     short    linecount;
  649.     
  650.     insbyte = 1;
  651.     
  652.     _rstrcpy( &charmap[LOC_Y][CUR_X + insbyte], &charmap[LOC_Y][CUR_X] );
  653.     cmemset( &charmap[LOC_Y][CUR_X], SPACE, insbyte);
  654.     _rmemcpy( &charmap2[LOC_Y][CUR_X + insbyte], &charmap2[LOC_Y][CUR_X], (80 - (CUR_X + insbyte)) * 2 ); 
  655.     
  656.     linecount = 0;
  657.     while( ((LOC_Y    + linecount) < 40) && (insbyte != 0) ){
  658.         MAX_X[LOC_Y + linecount] = MAX_X[LOC_Y + linecount] + insbyte; 
  659.         movebyte = 0;
  660.         while( ( MAX_X[LOC_Y + linecount] - movebyte ) > ( SIZ_X - 1 ) ){
  661.             pcharmap2 = &charmap2[LOC_Y + linecount][ MAX_X[LOC_Y + linecount] - movebyte ];
  662.             if( *pcharmap2 == 0 )
  663.                 movebyte += 1;
  664.             else
  665.                 movebyte += 2;    
  666.         }
  667.         if( movebyte > 0 ){
  668.             move_right( movebyte, linecount );
  669.             MAX_Y = LOC_Y + linecount + 1;
  670.         }
  671.         if( (CUR_Y + linecount) <= (SIZ_Y - 1) )
  672.             move_putchr( linecount, insbyte );
  673.         insbyte = movebyte;
  674.         linecount++;
  675.     }    
  676. }
  677.  
  678. void    chr_out(char ch)
  679. {
  680.     register WIND *wp=act_wind;
  681.     char    *pch = &ch;
  682.     char    *pcharmap = &charmap[LOC_Y][CUR_X];
  683.     short    *pcharmap2 = &charmap2[LOC_Y][CUR_X];
  684.     
  685.     if( ( INS_STAT == ON ) && ( ( KAN_COD <= 0 ) || ( ch != SPACE ) ) )
  686.         ins();
  687.     
  688.     DSP_BUF[DSP_LEN++] = ch;
  689.     
  690.     if( (KAN_COD == 0) || (ch != SPACE) ){      
  691.         *pcharmap = *pch;
  692.         pcharmap++;
  693.         if( (LOC_Y == MAX_Y) && (CUR_X >= MAX_X[LOC_Y]) )
  694.             *pcharmap = (char)0x00;
  695.         if( KAN_COD != 0 ){
  696.             if( KAN_COD > 0 )
  697.                 *pcharmap2 = 0x01;
  698.             else                            
  699.                 *pcharmap2 = 0x02;
  700.         } else
  701.             *pcharmap2 = 0x00;
  702.            if( CUR_X > MAX_X[LOC_Y] )
  703.                MAX_X[LOC_Y] = CUR_X;
  704.     }
  705.     
  706.     if ( ++CUR_X >= SIZ_X ) {
  707.         CUR_X = 0;
  708.         if( ++LOC_Y > MAX_Y )
  709.             MAX_Y = LOC_Y;
  710.         if ( ++CUR_Y >= SIZ_Y ) {
  711.             CUR_Y = SIZ_Y - 1;
  712.             roll_down();
  713.         } else
  714.             cflush();
  715.     } 
  716. }
  717.  
  718. void    putch(char ch)
  719. {
  720.     register WIND *wp=act_wind;
  721.     FILE    *fp;
  722.     short    i, j;
  723.     char    para[12];
  724.     
  725.     EGB_writePage( work, 0x40 );
  726.     
  727.     if ( KAN_COD != 0 ) {
  728.         if ( iskanji2(ch) ) {
  729.             if ( CUR_X == (SIZ_X - 1) )
  730.                 chr_out(' ');
  731.             chr_out(KAN_COD);
  732.             KAN_COD *= (-1);
  733.             chr_out(ch);
  734.             KAN_COD = 0;
  735.             return;
  736.         }
  737.         KAN_COD = 0;
  738.     }
  739.     
  740.     if ( iskanji(ch) && ( ch != DEL ) ) {
  741.         KAN_COD = ch;
  742.         return;
  743.     }
  744.     
  745.     
  746.     if ( ( ch >= SPACE) && ( ch != DEL ) ) {
  747.         chr_out(ch);
  748.         return;
  749.     }
  750.     
  751.     switch(ch) {
  752.     case ESC:
  753.         fp = fopen("a:charmap.txt", "w");
  754.         fprintf( fp, "CUR_X         %d\n", CUR_X);
  755.         fprintf( fp, "LOC_Y         %d\n", LOC_Y);
  756.         fprintf( fp, "SIZ_X - 1     %d\n", SIZ_X - 1);
  757.         fprintf( fp, "MAX_X[LOC_Y]  %d\n", MAX_X[LOC_Y]);
  758.         for( i = 0; i < 40; i++ ){
  759.             fputx( &charmap[i][0], fp); 
  760.             for( j = 0; j < 80; j++ )
  761.                 fprintf( fp, "%d", charmap2[i][j] );
  762.             fputc( '\n', fp );    
  763.         }
  764.         fclose( fp );    
  765.     case RIGHT:  
  766.         cur_right();
  767.         break;
  768.     case LEFT:
  769.         cur_left();
  770.         break;
  771.     case UP:
  772.         cur_up();
  773.         break;
  774.     case DOWN:
  775.         cur_down();
  776.         break;
  777.     case INS:      
  778.         EGB_paintMode( work, 0x22 );
  779.         EGB_color( work, 0, BOXCOL );
  780.         EGB_color( work, 2, BOXCOL );
  781.         WORD( para + 0 ) = 33.5 * 16;
  782.         WORD( para + 2 ) = 28.5 * 16 + 1;
  783.         WORD( para + 4 ) = 34.5 * 16;
  784.         WORD( para + 6 ) = 28.5 * 16 + 18;
  785.         EGB_rectangle( work, para );
  786.         if( INS_STAT == ON ){
  787.             INS_STAT = OFF;
  788.             strcpy( para + 6, " " );
  789.         } else {
  790.             INS_STAT = ON;     
  791.             strcpy( para + 6, "挿" );
  792.         }
  793.         EGB_color( work,0,CHR_COL);
  794.         EGB_textSpace( work, 0 );
  795.         EGB_fontStyle( work, 0 );
  796.         WORD( para + 0 ) = 33.5 * 16;
  797.         WORD( para + 2 ) = 29.5 * 16;
  798.         WORD( para + 4 ) = 2;
  799.         EGB_sjisString( work, para );
  800.         break;
  801.     case BS:
  802.         if( cur_left() )
  803.             del();
  804.         break;
  805.        case DEL:
  806.            del();
  807.            break;
  808.     default:
  809.         break;
  810.     }
  811.  
  812. }
  813.  
  814. void    getstr( char *sret )
  815. {
  816.     short    i;
  817.     
  818.     *sret = (char)0x00;
  819.     for( i = 0; ( MAX_Y >= i ) && ( i < 40 ); i++ )
  820.         strcat( sret, &charmap[i][0] );
  821.     
  822. }
  823.  
  824. /*********** 32K 
  825. static unsigned int dmy_pal[]={
  826.     0x00007FFF,0x000c7FFF,0x01807FFF,0x018c7FFF,
  827.     0x30007FFF,0x300c7FFF,0x31807FFF,0x318c7FFF,
  828.     0x42107FFF,0x00187FFF,0x03007FFF,0x03187FFF,
  829.     0x60007FFF,0x60187FFF,0x63007FFF,0x63187FFF };
  830. ************/
  831.  
  832. static unsigned int dmy_pal[]={
  833.     0x0000000F,0x0001000F,0x0002000F,0x0003000F,
  834.     0x0004000F,0x0005000F,0x0006000F,0x0007000F,
  835.     0x0008000F,0x0009000F,0x000A000F,0x000B000F,
  836.     0x000C000F,0x000D000F,0x000E000F,0x000F000F };
  837.  
  838. void    putstr(short pos,short len,char *str,char *att)
  839. {
  840.     static short    bak_len=0;
  841.     static char   *bak_buf[128];
  842.     register WIND *wp=act_wind;
  843.     short           i,x,y,n,m;
  844.     char          *p;
  845.     char          para[16];
  846.  
  847.     for ( i = 0 ; i < bak_len ; i++ ) {
  848.     EGB_putBlock(work,0,bak_buf[i]);
  849.     free(bak_buf[i]);
  850.     }
  851.     cflush();
  852.     bak_len = 0;
  853.     x = CUR_X; y = CUR_Y;
  854.     if ( (m = len) > 0 && len == pos )
  855.     m++;
  856.     for ( i = 0 ; i < m ; i += n ) {
  857.     n = ((i < len && iskanji((char)*str)) ? 2:1);
  858.  
  859.     if ( (x + n) > SIZ_X ) {
  860.         x = 0;
  861.         y++;
  862.     }
  863.  
  864.     if ( (p = (char *)malloc(FNT_X * FNT_Y * n * PIX_BYTE + 14)) == NULL )
  865.         break;
  866.         DWORD(p+0) = (unsigned int)(p+14);
  867.         WORD(p+4) = 0x014;            /* Data Selecter */
  868.         WORD(p+6) = TOP_X + x * FNT_X;
  869.         WORD(p+8) = TOP_Y + y * FNT_Y;
  870.         WORD(p+10) = WORD(p+6) + n * FNT_X - 1;
  871.         WORD(p+12) = WORD(p+8) + FNT_Y - 1;
  872.         EGB_getBlock(work,p);
  873.     bak_buf[bak_len++] = p;
  874.  
  875.     if ( i < len ) {
  876.             EGB_paintMode(work,0x22);
  877.             EGB_color(work,0, ROAKCOL/*dmy_pal[*att]>>16*/);
  878.             EGB_color(work,2, ROAKCOL/*dmy_pal[*att]>>16*/);
  879.             WORD(para+0) = WORD(p+6);
  880.             WORD(para+2) = WORD(p+8);
  881.             WORD(para+4) = WORD(p+10);
  882.             WORD(para+6) = WORD(p+12);
  883.             EGB_rectangle(work,para);
  884.  
  885.             EGB_color(work,0,dmy_pal[*att]&0xFFFF);
  886.             EGB_textSpace(work,FNT_X - 8);
  887.             EGB_fontStyle(work,FNT_STL);
  888.             WORD(para+0) = WORD(p+6);
  889.             WORD(para+2) = WORD(p+8) + (FNT_Y - 2);
  890.             WORD(para+4) = n;
  891.             *(para+6) = *str;
  892.             *(para+7) = *(str+1);
  893.             EGB_sjisString(work,para);
  894.             str += n;
  895.            att += n;
  896.     }
  897.  
  898.     if ( i == pos ) {
  899.         EGB_color(work,0,CUR_COL);
  900.         WORD(para+0) = WORD(p+6);
  901.         WORD(para+2) = WORD(p+12);
  902.         WORD(para+4) = WORD(p+10);
  903.         WORD(para+6) = WORD(p+12);
  904.         EGB_rectangle(work,para);
  905.     }
  906.  
  907.     if ( (x += n) >= SIZ_X ) {
  908.         x = 0;
  909.         y++;
  910.     }
  911.     }
  912. }
  913. void    putsys(short len,char *str,char *att)
  914. {
  915.     static short  bak_len=0;
  916.     static char   *bak_buf;
  917.     register WIND *wp=act_wind;
  918.     short         i,x,y,n;
  919.     char          *p;
  920.     char          para[16];
  921.  
  922.     if ( bak_len > 0 ) {
  923.         EGB_putBlock(work,0,bak_buf);
  924.         free(bak_buf);
  925.     }
  926.  
  927.     bak_len = 0;
  928.     if ( len == 0 )
  929.     return;
  930.  
  931.     if ( (p = bak_buf = 
  932.      (char *)malloc(FNT_X * FNT_Y * len * PIX_BYTE + 14)) == NULL )
  933.     return;
  934.  
  935.     DWORD(p+0) = (unsigned int)(p+14);
  936.     WORD(p+4) = 0x014;            /* Data Selecter */
  937.     WORD(p+6) = x = TOP_X;
  938.     WORD(p+8) = y = BTM_Y + 8;
  939.     WORD(p+10) = x + len * FNT_X - 1;
  940.     WORD(p+12) = y + FNT_Y - 1;
  941.     EGB_getBlock(work,p);
  942.     bak_len = len;
  943.  
  944.     for ( i = 0 ; i < len ; i += n ) {
  945.     n = (iskanji((char)*str) ? 2:1);
  946.  
  947.         EGB_paintMode(work,0x22);
  948.         EGB_color(work,0,ROAKCOL/*dmy_pal[*att]>>16*/);
  949.         EGB_color(work,2,ROAKCOL/*dmy_pal[*att]>>16*/);
  950.         WORD(para+0) = x;
  951.         WORD(para+2) = y;
  952.         WORD(para+4) = x + n * FNT_X - 1;
  953.         WORD(para+6) = y + FNT_Y - 1;
  954.         EGB_rectangle(work,para);
  955.  
  956.         EGB_color(work,0,dmy_pal[*att]&0xFFFF);
  957.         EGB_textSpace(work,FNT_X - 8);
  958.         EGB_fontStyle(work,FNT_STL);
  959.         WORD(para+0) = x;
  960.         WORD(para+2) = y + (FNT_Y - 2);
  961.         WORD(para+4) = n;
  962.         *(para+6) = *str;
  963.         *(para+7) = *(str+1);
  964.         EGB_sjisString(work,para);
  965.         str += n;
  966.        att += n;
  967.     x += (FNT_X * n);
  968.     }
  969. }
  970. void    putmode(short md,short sf,char *str)
  971. {
  972.     register WIND *wp=act_wind;
  973.     char    para[40];
  974.     
  975.     EGB_writePage( work, 0x40 );
  976.     EGB_paintMode( work, 0x22 );
  977.     
  978.     EGB_color( work, 0, DBXCOL );
  979.     EGB_color( work, 2, BOXCOL );
  980.     WORD( para + 0 ) = 32.5 * 16;
  981.     WORD( para + 2 ) = 28.5 * 16;
  982.     WORD( para + 4 ) = 39.5 * 16;
  983.     WORD( para + 6 ) = 28.5 * 16 + 19;
  984.     EGB_rectangle( work, para );
  985.  
  986.     WORD( para + 0 ) = 2;
  987.     WORD( para + 2 ) = 32.5 * 16;
  988.     WORD( para + 4 ) = 28.5 * 16;
  989.     WORD( para + 6 ) = 32.5 * 16;
  990.     WORD( para + 8 ) = 28.5 * 16 + 18;
  991.     EGB_color( work, 0, UBXCOL );
  992.     EGB_color( work, 2, UBXCOL );
  993.     EGB_connect( work, para );
  994.  
  995.     if( INS_STAT == ON )
  996.         strcpy( para + 6, "挿" );
  997.     else    
  998.         strcpy( para + 6, " " );
  999.     strcat( para + 6, str );
  1000.     EGB_color( work,0,CHR_COL);
  1001.     EGB_textSpace( work, 0 );
  1002.     EGB_fontStyle( work, 0 );
  1003.     WORD( para + 0 ) = 33.5 * 16;
  1004.     WORD( para + 2 ) = 29.5 * 16;
  1005.     WORD( para + 4 ) = 11;
  1006.     EGB_sjisString( work, para );
  1007. }
  1008.